package queue_stack;


import java.util.Stack;

/**
 *  验证栈序列 (2024 百度 地图 资深岗)
 *
 * https://leetcode.cn/problems/validate-stack-sequences/
 */
public class ValidateStackSequences {

    Stack<Integer> data=new Stack<>();

    public boolean validateStackSequences(int[] pushed, int[] popped) {
        int j=0;
        for (int i = 0; i < pushed.length; i++) {
            data.push(pushed[i]);
            while (!data.isEmpty()&&data.peek()==popped[j]){
                data.pop();
                j++;
            }
        }

        return data.isEmpty();
    }
}
